package com.byx.imclientutil.config;

import androidx.annotation.NonNull;

/**
 * ImProperties
 * 属性配置
 * @author Superb
 * @date 2021/2/9 19:23
 */
public class ImProperties {
    private String host;// 服务器ip
    private int port; //端口号
    private int connectTimeout;// 连接超时时间，单位：毫秒
    private int reconnectInterval;// 重连间隔时间，单位：毫秒
    private int reconnectCount;// 单个地址一个周期最大重连次数
    private int foregroundHeartbeatInterval;// 应用在前台时心跳间隔时间，单位：毫秒
    private int backgroundHeartbeatInterval;// 应用在后台时心跳间隔时间，单位：毫秒
    private boolean autoResend;// 是否自动重发消息
    private int resendInterval;// 自动重发间隔时间，单位：毫秒
    private int resendCount;// 消息最大重发次数

    public ImProperties(Builder builder) {
        this.host=builder.host;
        this.port= builder.port;
        this.connectTimeout= builder.connectTimeout;
        this.reconnectInterval=builder.reconnectInterval;
        this.reconnectCount= builder.reconnectCount;
        this.foregroundHeartbeatInterval= builder.foregroundHeartbeatInterval;
        this.backgroundHeartbeatInterval= builder.backgroundHeartbeatInterval;
        this.autoResend= builder.autoResend;
        this.resendInterval= builder.resendInterval;
        this.resendCount= builder.resendCount;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public int getReconnectInterval() {
        return reconnectInterval;
    }

    public int getReconnectCount() {
        return reconnectCount;
    }

    public int getForegroundHeartbeatInterval() {
        return foregroundHeartbeatInterval;
    }

    public int getBackgroundHeartbeatInterval() {
        return backgroundHeartbeatInterval;
    }

    public boolean isAutoResend() {
        return autoResend;
    }

    public int getResendInterval() {
        return resendInterval;
    }

    public int getResendCount() {
        return resendCount;
    }

    @NonNull
    @Override
    public String toString() {
        return "ImProperties{" +
                "host='" + host + '\'' +
                ", port=" + port +
                ", connectTimeout=" + connectTimeout +
                ", reconnectInterval=" + reconnectInterval +
                ", reconnectCount=" + reconnectCount +
                ", foregroundHeartbeatInterval=" + foregroundHeartbeatInterval +
                ", backgroundHeartbeatInterval=" + backgroundHeartbeatInterval +
                ", autoResend=" + autoResend +
                ", resendInterval=" + resendInterval +
                ", resendCount=" + resendCount +
                '}';
    }

    public static class Builder{
        private String host;// 服务器ip
        private int port; //端口号
        private int connectTimeout;// 连接超时时间，单位：毫秒
        private int reconnectInterval;// 重连间隔时间，单位：毫秒
        private int reconnectCount;// 单个地址一个周期最大重连次数
        private int foregroundHeartbeatInterval;// 应用在前台时心跳间隔时间，单位：毫秒
        private int backgroundHeartbeatInterval;// 应用在后台时心跳间隔时间，单位：毫秒
        private boolean autoResend;// 是否自动重发消息
        private int resendInterval;// 自动重发间隔时间，单位：毫秒
        private int resendCount;// 消息最大重发次数

        public Builder() {
            this.host=ImConfig.HOST;
            this.port=ImConfig.PORT;
            this.connectTimeout=ImConfig.CONNECT_TIMEOUT;
            this.reconnectInterval=ImConfig.RECONNECT_INTERVAL;
            this.reconnectCount=ImConfig.RECONNECT_COUNT;
            this.foregroundHeartbeatInterval=ImConfig.FOREGROUND_HEARTBEAT_INTERVAL;
            this.backgroundHeartbeatInterval=ImConfig.BACKGROUND_HEARTBEAT_INTERVAL;
            this.autoResend=ImConfig.AUTO_RESEND;
            this.resendInterval=ImConfig.RESEND_INTERVAL;
            this.resendCount=ImConfig.RESEND_COUNT;
        }

        public Builder setHost(String host) {
            this.host = host;
            return this;
        }

        public Builder setPort(int port) {
            this.port = port;
            return this;
        }

        public Builder setConnectTimeout(int connectTimeout) {
            this.connectTimeout = connectTimeout;
            return this;
        }

        public Builder setReconnectInterval(int reconnectInterval) {
            this.reconnectInterval = reconnectInterval;
            return this;
        }

        public Builder setReconnectCount(int reconnectCount) {
            this.reconnectCount = reconnectCount;
            return this;
        }

        public Builder setForegroundHeartbeatInterval(int foregroundHeartbeatInterval) {
            this.foregroundHeartbeatInterval = foregroundHeartbeatInterval;
            return this;
        }

        public Builder setBackgroundHeartbeatInterval(int backgroundHeartbeatInterval) {
            this.backgroundHeartbeatInterval = backgroundHeartbeatInterval;
            return this;
        }

        public Builder setAutoResend(boolean autoResend) {
            this.autoResend = autoResend;
            return this;
        }

        public Builder setResendInterval(int resendInterval) {
            this.resendInterval = resendInterval;
            return this;
        }

        public Builder setResendCount(int resendCount) {
            this.resendCount = resendCount;
            return this;
        }

        public ImProperties build(){
            return new ImProperties(this);
        }
    }
}
